<?php
error_reporting(E_ALL ^ E_NOTICE);
class cls_admin_forms{ //class for administrative page only

	public function add_edit($user_id,$action){ //function_edit_add_user values
		include_once 'db_conn.php';                                                                                          
		include_once 'forms.php';
		if($action=='edit'){
			$sql_str1="select * from tbl_usr_crd where un='{$user_id}'";
			$sql_qry1=mysql_query($sql_str1) or die(mysql_error());
			$row=mysql_fetch_array($sql_qry1);
		}
		?>
		<form name="form1" method="POST" action="form_handler.php">
		<input type="hidden" name="utype" value="2">
		<input type=hidden name="admin" value="user_action">
		<?php if($user_id!=''){ ?><input type="hidden" name="user_id" value="<?php echo $user_id?>"> <?php } ?> 
		<?php if($action=='add'){
			//declare all the ouotgoing variables for use in processing module under form_handler.php (see variables below)
			// post['admin']
			//case:user_action
			//condition:add
			?>
			<!--declaration starts here!-->
			<input type="hidden" name="action" value="add">
			<?php   
		}elseif($action=="edit"){
			//declare all the ouotgoing variables for use in processing module under form_handler.php
			// post['admin']
			//case:user_action
			//condition:edit
			?><!--declaration starts here!-->
			<input type="hidden" name="action" value="edit">
			<input type="hidden" name="user_id" value="<?php echo $row['un']?>">
			<input type="hidden" name="profile_id" value="<?php echo $row['profile_id']?>">
			<?php
		} ?>
			<table border="0">
			<tr><td>Username:&nbsp;</td><td><input type="text" size="50" maxlength="50" name="UserName" value="<?php echo $row['un']?>"></td> </tr>
			<tr><td><?php if($action=='edit'){echo "Old";}?>&nbsp;Password:&nbsp;</td><td><input type="password" name="UserPass" value="<?php echo $row['pwd']?>" maxlength="50" size="50"/></td></tr>
			<tr><td><?php if($action=='add'){echo "Confirm";}else{echo "New";}?>&nbsp;Password:&nbsp;</td><td><input type="password" name="UserPass2" size="50" maxlength="50"/></td></tr>
			<?php if($action=='edit'){ ?>
			<tr><td>&nbsp;Confirm New Password:&nbsp;</td><td><input type="password" name="UserPass3" size="50" maxlength="50"/></td></tr>
			<?php } ?>
			<tr><td>Full Name:&nbsp;</td><td><input type=text name="emp_name" value="<?php echo $row['fullname']?>" size="50" maxlength="50"></td></tr>
			<tr><td>Office Name:&nbsp;</td><td><?php echo cls_admin_forms::get_ofc_names($ofc_name)?></td></tr>   
			<tr><td colspan="2">&nbsp;</td></tr>
			<tr><td colspan="2"><center><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button"><?php if($action=='add'){echo 'Add';}else{echo "Save";}?></a></span></center></td></tr>
			</table>
		</form>
		<?php
		}//add or edit user data
		
	protected function get_ofc_names($ofc_name){
		include_once 'db_conn.php';
		$sql_str1="select * from codes where category='ofc_type' order by descr asc";
		$sql_qry1=mysql_query($sql_str1) or die(mysql_error());
		?><select name="ofc_name"><option value="" <?php if($ofc_name==''){echo "selected";}?>>Select Office Name</option> <?php
		while ($row=mysql_fetch_array($sql_qry1)){
			?><option value="<?php echo $row['code']?>" <?php 
				if(trim($ofc_name)==$row['descr']){ echo "selected"; }?>>
				<?php echo strtoupper($row['descr'])?></option><?php            
		}?></select>
		<?php 
	} //get office names for the user
	
	public function msg($message,$color){
		?>
		<center><h3><font color="<?php echo $color?>"><?php echo $message?></font></h2></center>
		<?php return(0);
	} //show error messages
	
	public function view(){
		include_once 'db_conn.php';
		$sql_str1="select * from tbl_usr_crd order by ofc_name asc";
		$sql_qry1=mysql_query($sql_str1) or die(mysql_error());
		?>
		<table align="center">
			<tr>
				<td align="center">Delete</td>
				<td align="center">Edit</td>
				<td align="center">Full Name</td>
				<td  align="center">Office Name</td>
				<td align="center">User Name</td>
				<td align="center">Password</td>
			</tr>
		
		<?php
		while($row=mysql_fetch_array($sql_qry1)){
			?>
			<tr>
				<!--icon here for delete!-->
				<td align="center"><a href="admin.php?req=del&user_id=<?php echo $row['un']?>" title="delete user"><img src="icon/icon_del.jpg"></a></td>
				<!--icon here for delete!-->
				<td align="center"><a href="admin.php?req=edit&user_id=<?php echo $row['un']?>" title="edit user"><img src="icon/icon_edit.jpg"></a></td>
				<td align="center"><?php echo strtoupper($row['fullname'])?></td>
				<td align="center"><?php echo strtoupper($row['ofc_name'])?><!--office Name!--></td>
				<td align="center"><?php echo $row['un']?><!--User Name!--></td>
				<td align="center"><?php echo $row['pwd']?><!--Password!--></td>
			</tr>
			<?php }?> </table>
			<?php
		
	}//users/names listings
		
}

//class for administrative page only ends here

class cls_forms{ //general forms starts here cls_forms::error_msg(msg,return )

/*
*
*/

//todo: [start] stage to commit for remote PS (status: in progress)
public function optCreateReadingSheet(){
	include_once 'cls_codes.php';
	include_once 'db_conn.php';
	?>
	<form id="form1" name="form1" method="POST" action="form_handler.php">
	<input type="hidden" name="bill" value="CreateReadingSheet"> 
		<table width="100%">
			<tr><td colspan="2"><center>Please select Barangay to Create Reading Sheet for the month <?php echo cls_misc::toString(date('m'),'month');?></center></td></tr>
			<tr>
				<td><center>Barangay
				<select name="barangay_code">
					
				<?php
						$barangay_names=cls_misc::getOptBarangayNames();
						foreach($barangay_names as $key=>$value){
							echo "<option value='{$value['codes_value']}'>".$value['descr_value']."</option>";
						}
						  ?> 
				</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<span class="art-button-wrapper"><span class="art-button-l">
</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Create</a></span></td></tr>
		</table>
	</form>
	<?php
}

//todo: [end] stage to commit for remote PS
public function ProfileWindow($account_number=null,$iteration_number=null){
	include_once 'db_conn.php';
	?>
		<!--sample2!-->
		<div id="basic-modal-content<?php echo $iteration_number?>">
			<h4><center>Basic Modal Dialog_test2</center></h4> 
			<p>Modal Dialog test_2</p>    
			<table align="center" border='0' width="100%" cellspacing="0" cellpadding="0">
				<tr><td><hr/></td></tr>
				<tr> <td align="center">Test Table for iteration number = <?php echo $iteration_number?></td></tr>
				<tr><td><hr/></td></tr>
			</table>
		</div>
		
		<!-- preload the images -->
		<div style='display:none'>
			<img src='images/x.png' alt='' />
		</div>
		</div>
	<?php
}

/*	
*  option for month to be used for visual presentation of the data such as graph
*/
	public function vis_report_opt($criteria,$table_name){
		include_once 'db_conn.php';
		include_once 'cls_codes.php';
		//$sql_str="select distinct(adlaw) from {$table_name} group by {$criteria} asc";
		$sql_str="select distinct(adlaw) from {$table_name}";
		$sql_qry=mysql_query($sql_str) or die(mysql_error());
		?>
		<select name="year-month">
			<?php
				while($row=mysql_fetch_array($sql_qry)){
					$option_value=$row['adlaw'];
					$data_option=explode('-',$option_value);
					$month_str=strtoupper(cls_misc::toString($data_option[1],"month"));
					$year=$data_option[0];
					?>
					<option value="<?php echo $option_value;?>"><?php echo $month_str.'-'.$year?></option>
					<?php
				}
			?>
		</select>
		<?php
	}

	public function bill_accnt(){
		?>
		<form name="form1" action="form_handler.php" method="POST">
		<input type="hidden" name="bill" value="pass_accnt">
		<p>
		<b>Enter Account Number</b>:&nbsp;<input type="text" name="accnt_no"  size="30" maxlength="20">&nbsp;&nbsp;
		<span class="art-button-wrapper"><span class="art-button-l">
</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Search</a></span><br /></p>
</form>
	<table id="butangan" class="datagrid"></table>
		<?php
	}

	public function error_msg($msg,$return_link){
		?>
		<div class="art-blockheader">
		   <h3 class="t"><font color="red"><?php echo $msg?></font></h3>
		</div>

		<p align="center"> <span class="art-button-wrapper"><span class="art-button-l">
</span><span class="art-button-r"></span><a href="<?php echo $return_link?>" class="art-button">Back</a></span><br /></p>

		<?php
	}

	public function ListBrgy(){
		include_once 'db_conn.php';
		$sql_str="select * from codes where category='Barangay' order by descr asc";
		$sql_qry=mysql_query($sql_str) or die(mysql_error());
		?>
		<br><br>
		<form name="form1" action="form_handler.php" method="POST">
		<input type="hidden" name="bill" value="show_brgy">
		<table class="art-article" align="center" cellpadding="0" cellspacing="0">
			<tr>
				<th colspan="2">Select List of Barangay for Billing Downloads</th>
			</tr>
			<tr>
				<td>
					<select name="brgy_opt">
					<?php while ($row=mysql_fetch_array($sql_qry)) {?>
						<option value="<?php echo $row['code']?>"><?php echo $row['descr']?></option>
					<?php } ?>
					</select>
				</td>
				<td><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Show</a></span></td>
			</tr>
		</table>
		</form>
		<?php
	}

	public function show_accnt_billings($barangay_code){
		include_once 'db_conn.php';
		include_once 'date_time.php';
		include_once 'cls_bill.php';
		include_once 'cls_codes.php';
		//TODO: [start] stage for commit to remote PS
		$sql_str="select * from profile where address_brgy='{$barangay_code}' order by applicant asc";
		//TODO: [end] stage for commit to remote PS
		$sql_qry=mysql_query($sql_str) or die(mysql_error());
		//echo "record_count=".mysql_num_rows($sql_qry);
		if (mysql_num_rows($sql_qry)!=0) { //data found!
		?>
		<form name="form1" action="form_handler.php" method="POST">
		<input type="hidden" name="bill" value="dl_bill">
			<table cellpadding="0" cellspacing="0" align="center">
			<tr><td colspan="5"><strong>List of UnPaid Bills Created for Barangay <?php echo cls_misc::toString($barangay_code,"Barangay");?></strong></td></tr>
				<tr>
					<!--<td><strong>ID</strong></td>-->
					<td><b><center>Account No.</center></b></td>
					<td><b>Account Name</b></td>
					<td><b>Last Bill Created</b></td>
					<td><b>Bill Amount</b></td>
					<td><b><center>Action</center></b></td>
					
				</tr>
				<?php
				while ($row=mysql_fetch_array($sql_qry)) {
					$legder_table=cls_misc::ConvertToTableName($row['acct_no']);
//					echo "Test:ledger table={$legder_table}"."&nbsp;&nbsp;&nbsp;&nbsp;";
					$sql_GetAllNonPaidBills="SELECT * FROM {$legder_table} WHERE OR_num='' or OR_num='0' or OR_num is null";
					$qry_GetAllNonPaidBills=mysql_query($sql_GetAllNonPaidBills) or die(mysql_error());
					if(mysql_numrows($qry_GetAllNonPaidBills)!= 0){
//						echo "Test:NonPaidBills=".mysql_numrows($qry_GetAllNonPaidBills)."<br>";
						while($row_GetAllNonPaidBills=mysql_fetch_array($qry_GetAllNonPaidBills)){
							$i=$i + 1; if ($i % 2==0) { echo "<tr background=\"#FAF4D1\">"; }else{ echo "<tr>"; }                   
					 //start iterations 
					 ?>
					<td><?php echo $row['acct_no']?></td>
					<td><?php echo $row['applicant']?></td>
					<td><center>
					<?php echo cls_misc::toString(cls_date_get::extract_month($row_GetAllNonPaidBills['reading_date']),"month").'-'.
					cls_date_get::extract_year($row_GetAllNonPaidBills['reading_date'])?>
					</center></td>
					<td><?php echo cls_misc::gFormatNumber($row_GetAllNonPaidBills['bill_amnt']) ?> </td>
					<td><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span>
				<a href="download_billing.php?request=init_dl&accnt_no=<?php echo base64_encode($row['acct_no'])?>&last_bill=<?php echo base64_encode($row_GetAllNonPaidBills['reading_date'])?>" class="art-button">Download</a>
				</span></td>
					
					</tr><?php
							
						}
					}
				}}
					
					
					//---old codes below
/*					$i=$i + 1;
					if ($i % 2==0) {
					?><tr background="#FAF4D1"><?php
					}else{
						?><tr><?php
					}
					?>
						<td><?php echo $i?></td>
						<td><?php echo $row['acct_no']?></td>
						<td><?php echo $row['applicant']?></td>
						<td><center><?php echo cls_misc::toString(cls_date_get::extract_month(cls_bill_get::last_bill_created($row['acct_no'])),"month").'-'. cls_date_get::extract_year(cls_bill_get::last_bill_created($row['acct_no']))?>
							<input type="hidden" name="last_bill_created" value="<?php cls_bill_get::last_bill_created($row['acct_no'])?>"></center></td>
						<td><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span>
				<a href="download_billing.php?request=init_dl&accnt_no=<?php echo base64_encode($row['acct_no'])?>&last_bill=<?php echo base64_encode( cls_bill_get::last_bill_created($row['acct_no']))?>" class="art-button">Download</a>
				</span></td>
						<td><center><b><?php echo strtoupper(cls_bill_get::bool_dl($row['acct_no'],cls_bill_get::last_bill_created($row['acct_no'])))?></b></center></td>
					</tr>
					<?php
				}
				?>

			</table>
		</form>
		<?php }else {
			?><br><br> <table cellpadding="0" cellspacing="0" align="center">
				<tr>
					<td><strong>ID</strong></td>
					<td><b><center>Account No.</center></b></td>
					<td><b>Account Name</b></td>
					<td><b>Last Bill Created</b></td>
					<td><b><center>Action</center></b></td>
					<td><b>Downloaded</b></td>
				</tr> <tr><td colspan="6"><center><font color="Red"><h3>No Data Found!</h3></font></center></tr>
				</table>
			<?php

		}
	*/
	?></table></form> <?php
	}
	public function frm_login_generic(){
		?>
		<br>
		<form name="form1" method="POST" action="form_handler.php">
			<input type="hidden" name="generic" value="login">
			<center>
			<table  align="center">
				<tr>
					<th colspan="2" align="center">User Login Required</th>
				</tr>
				<tr>
					<td>Username:</td>
					<td><input type="text" name="usn" size="20" maxlength="20"></td>
				</tr>
				<tr>
					<td>Password:</td>
					<td><input type="password" name="usp" size="20" maxlength="20"></td>
				</tr>
				<tr>
					<td colspan="2"><center><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Login</a></span></center></td>
				</tr>
			</table>
			</center>
		</form>
		<?php
	}

	public function frm_login($LinkName='',$LinkID='',$form_method=''){
		//cashier department: linkname=cashier,linkid=const "login",form_method=post
		?>
		<br>
		<form name="form1" method="<?php echo strtoupper($form_method) ?>" action="form_handler.php">
			<input type="hidden" name="<?php echo $LinkName?>" value="login">
			<center>
			<table  align="center">
				<tr>
					<th colspan="2" align="center">User Login Required</th>
				</tr>
				<tr>
					<td>Username:</td>
					<td><input type="text" name="usn" size="20" maxlength="20"></td>
				</tr>
				<tr>
					<td>Password:</td>
					<td><input type="password" name="usp" size="20" maxlength="20"></td>
				</tr>
				<tr>
					<td colspan="2"><center><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Login</a></span></center></td>
				</tr>
			</table>
			</center>
		</form>
		<?php
	}

	public function frm_cashier_acnt(){ //form to search for consumer account number
		?>
		<br>
		<center>
			<form name="form1" method="POST" action="form_handler.php">
			<input type="hidden" name="cashier" value="show_ledger1">
				<table>
					<tr>
						<th align="center">Enter Account Number</th>
					</tr>
					<tr>
						<td><input type="text" name="accnt" size="15" maxlength="15"></td>
					</tr>
					<tr>
						<td><center><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Show Ledger</a></span></center></td>
					</tr>
				</table>
			</form>
		</center><br><p align="center"><strong>OR</strong></p> <br>
		<!--payment through account search form-->
		<center>
				<form id="search">
				<table>
					<tr>
						<th align="center">Search Account Number</th>
					</tr>
					<tr>
						<td><input type="text" id="accnt" name="accnt" size="15" maxlength="15"></td>
					</tr>
					<tr>
						<td><center><span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:getdetails()"  class="art-button">Search</a></span></center></td>
					</tr>
				</table>
				</form>
				<div id="status"></div>
				<div id="results"></div>

		</center>
		
		<?php
	} //form to search for consumer account number

	
	
	public function show_ledger($account_number){ //show ledger for specific consumers using unsettled accounts
		//show consumer ledger
		include_once 'db_conn.php';
		include_once 'cls_user.php';
		include_once 'cls_bill.php';
		?>
		<center>
			<form name="form1" action="form_handler.php" method="POST">

				<center>Consumer Legder Summary</center>
				<!--user information !-->
				<?php cls_user_get::user_info($account_number); ?>
				<!--show unpaid bills only!-->
				<?php cls_bill_get::unsettled_bills($account_number);?>
			</form>
		</center>
		<?php  
		//return(void);
	}//show ledger for specific consumers using unsettled accounts

	public function frm_cashier_payment($account_number,$billing_month,$total_amount,$penalty){
		include_once 'db_conn.php';
		include_once 'cls_codes.php';
		include_once 'date_time.php';
		include_once 'cls_user.php';
		$consumer_ledger=cls_misc::sanitize_hyp(trim($account_number));
		$date_now=cls_date_get::date_now();
		cls_user_get::user_info($account_number);
		?>
		<br><br>
		<center>
		<form name="form1" method="POST" action="form_handler.php">
		<input type="hidden" name="cashier" value="payment">
		<table>
			<tr><th colspan="4">Cashier Payment Form</th></tr>
			<tr>
				<td>Billing Month:&nbsp;</td>
				<input type="hidden" name="billing_month" value="<?php echo $billing_month?>">
				<input type="hidden" name="acnt_no" value="<?php echo trim($account_number)?>">
				<input type="hidden" name="penalty" value="<?php echo $penalty?>">
				<td><strong><?php echo cls_misc::toString(cls_date_get::extract_month($billing_month),'month').'-'.cls_date_get::extract_year($billing_month)?></td>
				<td>Total Amount:&nbsp;</td>
				<td><input type="text" name="total_amnt" value="<?php echo number_format($total_amount,2,'.',',');?>" readonly></td>
			</tr>
			<tr>
				<td>OR Date:&nbsp;</td>
				<td><input type="text" name="or_date" value="<?php echo cls_date_get::date_now()?>" readonly></td>
				<td>OR No.&nbsp;</td>
				<td><input type="text" name="or_no" size="20" maxlength="20"></td>
			</tr>
			<tr>
				<td colspan="4"><center>
					<span class="art-button-wrapper"><span class="art-button-l">
				</span><span class="art-button-r"></span><a href="javascript:submitform()" class="art-button">Save</a></span></center>
				</td>
			</tr>
		</table>
		</form>
		</center>
		<?php

	}

	public function frm_opt_user($action){
		include_once 'db_conn.php';
		if ($action='edit') { //process request for data entry in the form below

		}
		?>
		<br>
		<form name="form1" method="POST" action="form_handler.php">
			<input type="hidden" name="generic" value="opt_user">
			<center>
				<table width="100%" cellpadding="0" cellspacing="0">
					<tr><th>User Credential Entry:Action=<?php echo $action?></th></tr>
					<tr><td>&nbsp;</td></tr>
					<tr>
						<td>Fullname:&nbsp;</td>
						<td><input type="text" name="fn" value="" size="30" maxlength="30"></td>
					</tr>
					<tr>
						<td>User Name:&nbsp;</td>
						<td><input type="text" name="usn" value="" size="20" maxlength="20"></td>
					</tr>
					<tr>
						<td>Password:&nbsp;</td>
						<td><input type="password" name="usp" size="20" maxlength="20" value=""></td>
						<td>Confirm:&nbsp;</td>
						<td><input type="password" name="usp2" size="20" maxlength="20" value=""></td>
					</tr>
					<tr>
						<td>Office Name:&nbsp;</td>
						<td><select name="ofc"><!-- create option from codes for office name values!--> </select></td>
					</tr>
				</table>
			</center>
		</form>
		<?php
	}
}

?>